<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="com.cms.biz.category.CategoryHelper"%>
<%@page import="com.cms.menu.MenuHelper"%>
<%@page import="java.sql.*, java.util.*, com.cms.config.*, com.cms.facade.*,com.cms.util.*,com.cms.bean.*,com.cms.database.DBHelper"%>
<%@page import="org.apache.log4j.Logger"%>
<%@taglib uri="/i18n-1.0" prefix="i18n"%>
<%@ taglib uri="/eccmtags" prefix="ec2m"%>
<%
	response.setContentType("text/html; charset=UTF-8");
	SysConfigBean sysbean = ApplicationHelper.getApplicationSysConfigBean(session);
	int menuId = StringHelper.isRequestParamEmptyInt(request, "menuId", 0);
	int categoryTypeId = StringHelper.isRequestParamEmptyInt(request, "categoryTypeId", CategoryTypeDef.NEW);
	List<CategoryBean> list = ApplicationHelper.getApplicationSubCategoryListById(session, categoryTypeId);
	
	List<RSFBean> v = RequestFacade.getResultList(request);

	String sortCol = request.getParameter("sortCol");
	if (sortCol == null)
		sortCol = " r.create_date ";
	String sortDir = request.getParameter("sortDir");
	String nextSortDir = Sorting.DSC;
	if (sortDir == null) {
		sortDir = Sorting.DSC;
		nextSortDir = Sorting.ASC;
	} else {
		if (sortDir.equals(Sorting.ASC))
			nextSortDir = Sorting.DSC;
		else
			nextSortDir = Sorting.ASC;
	}

	int current_page = 1;
	String current_page_str = request.getParameter("page");
	if (current_page_str != null) {
		current_page = Integer.parseInt(current_page_str);
	}


	int num_per_page = ConfigDef.NUM_OF_ITEMS_PER_PAGE;
	String num_per_page_str = request.getParameter("num_per_page");
	if (num_per_page_str != null) {
		num_per_page = Integer.parseInt(num_per_page_str);
	}

	int total_num = RequestFacade.getResultTotal(request);
	if (total_num == 0 && v != null) {
		total_num = v.size();
	}

	int item_per_page = num_per_page;
	int total_pages = total_num / item_per_page + 1;
	String cmd = "GetRSFList";
	
	String adv_title = Formater.formatText(request.getParameter("adv_title"));
	int adv_subcategory = StringHelper.isRequestParamEmptyInt(request, "adv_subcategory", -1);
	String adv_startDate = Formater.formatText(request.getParameter("adv_startDate"));
	String adv_endDate = Formater.formatText(request.getParameter("adv_endDate"));
%>
<i18n:bundle baseName="i18n-ebizport" locale="<%=SessionFacade.getLocale(session)%>"/>
<html>
<head>
<meta name="keywords" content="<%=sysbean.getWebKey()%>" />
<meta name="description" content="<%=sysbean.getWebDesc()%>" />
<meta name="viewport" content="width=device-width" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><%=sysbean.getWebName()%></title>
<link rel="stylesheet" href="<%=URLPath.CSS_DIR%>/global.css" type="text/css" media="screen" />
<link rel="stylesheet" href="<%=URLPath.CSS_DIR%>/admin.css" type="text/css" media="screen" />
<script type="text/javascript" src="<%=URLPath.JS_DIR%>/jquery-1.9.1.js"></script>
<script type="text/javascript" src="<%=URLPath.JS_DIR%>/main.js"></script>
<script type="text/javascript" src="<%=URLPath.JS_DIR%>/layer.js"></script>
<script type="text/javascript" src="<%=URLPath.JS_DIR%>/My97DatePicker/WdatePicker.js"></script>
<style type="text/css">
#advsreach{width:100%;height:30px;line-height:30px;color:#fff;background:#7f8c8d;}
</style>
<script type="text/javascript">
$(document).ready(function(){
	$(".scroll").css("max-height",$("#main_div",parent.document).height()-210);
	initCheckBoxAll();
});
function sortList(sortCol) {
	document.myform.cmd.value = "<%=cmd%>";
	document.myform.sortCol.value = sortCol;
	document.myform.sortDir.value = "<%=nextSortDir%>";
	document.myform.target = "_self";
	document.myform.submit();
}

function searchList() {
    document.myform.cmd.value = "<%=cmd%>";
    document.myform.sortCol.value = "<%=sortCol%>";
    document.myform.sortDir.value = "<%=sortDir%>";
    document.myform.page.value = "1";
    document.myform.target = "_self";
    document.myform.searchFlag.value = "true";
    document.myform.submit();
}

function getListByPageNum(page_no) {
    document.myform.cmd.value = "<%=cmd%>";
    document.myform.page.value = page_no;
    document.myform.sortCol.value = "<%=sortCol%>";
    document.myform.sortDir.value = "<%=sortDir%>";
    document.myform.target = "_self";
    document.myform.submit();
}

function getListBySelectedPage() {
    document.myform.cmd.value = "<%=cmd%>";
    var page_num = document.myform.page_num.options.selectedIndex;
    document.myform.page.value = document.myform.page_num.options[page_num].value;
    document.myform.sortCol.value = "<%=sortCol%>";
    document.myform.sortDir.value = "<%=sortDir%>";
	document.myform.target = "_self";
	document.myform.submit();
}
function edit(id){
	document.myform.rsfId.value = id;
    document.myform.nextPage.value = "/jsp/admin/editrsf.jsp";
	document.myform.doNothing.value = 'Y';
	document.myform.submit();
}
</script>
</head>
<body>
<form name="myform" action="<%=URLPath.ADMIN_URL %>"  method="post" target="_self">
<input type="hidden" name="token" value="<%=request.getAttribute("token")%>">
<input type="hidden" name="cmd" value=""/>
<input type="hidden" name="nextCmd" value=""/>
<input type="hidden" name="doNothing" value="N"/>
<input type="hidden" name="nextPage" value="">
<input type="hidden" name="menuId" value="<%=menuId %>"/>
<input type="hidden" name="categoryTypeId" value="<%=categoryTypeId %>"/>
<input type="hidden" name="sortCol" value="<%=sortCol%>">
<input type="hidden" name="sortDir" value="<%=sortDir%>">
<input type="hidden" name="page" value="<%=current_page %>">
<input type="hidden" name="rsfId" value="0">
<input type="hidden" name="searchFlag" value="">
<div class="admin-menu-nav">
   <ul >
     <li style="width:49.9%"><span class="menu-nav"><i18n:message key="now_position"/>:&nbsp;<%=MenuHelper.getMenuPath(session, menuId) %></span></li>
     <li style="width:50%">
         <span class="menu-button" onclick="deleteSelectRecords('DeleteRSF','<%=cmd %>')"><i18n:message key="batch_delete"/></span>
         <span class="menu-button" onclick="searchList()"><i18n:message key="select"/></span>
     </li>
   </ul>
</div>
<div id="advsreach" class="a-fadein">
&nbsp;&nbsp;&nbsp;&nbsp;
<i18n:message key="rsf.title" />: <input type="text" name="adv_title" value="<%=Formater.formatText(request.getParameter("adv_title")) %>" style="height:18px;"/>&nbsp;&nbsp;&nbsp;
<i18n:message key="type" />: 
         <select name="adv_subcategory" style="height:21px;">
            <option value="-1"><i18n:message key="all"/>
            <%
            if(list!=null&&list.size()>0){ 
                for(CategoryBean cBean:list){
             	   List<CategoryBean> subList = cBean.getChildCategoryBeans();
            %>
                   <optgroup label="<%=cBean.getName() %>">
                   <%
                   if(subList!=null&&subList.size()>0){ 
                	   for(CategoryBean subBean:subList){
                   %>
                       <option value="<%=subBean.getId() %>" <%=(adv_subcategory==subBean.getId())?"selected":"" %>><%=subBean.getName() %>
                   <%} }%>
                   </optgroup>                
            <%} }%>
         </select>&nbsp;&nbsp;&nbsp;
<i18n:message key="createdate" />: 
<input id="adv_startDate" name="adv_startDate" class="Wdate" type="text" value="<%=adv_startDate %>" onFocus="WdatePicker({maxDate:'#F{$dp.$D(\'adv_endDate\')||\'2020-10-01\'}'})"/> 
<%="\u81f3" %>
<input id="adv_endDate" name="adv_endDate" class="Wdate" type="text"  value="<%=adv_endDate %>" onFocus="WdatePicker({minDate:'#F{$dp.$D(\'adv_startDate\')}',maxDate:'2020-10-01'})"/>
</div>

<div class="mainDiv">
<div class="m-fixedheadertable">
	<table>
        <thead>
           <tr>
              <th width="20"><input type="checkbox" name="checkAll" value="" id="checkAll"/></th>
              <ec2m:sortI18NColumn sortCol="<%=sortCol%>" width="49%" name="title" title="Sort by title" sortDir="<%=sortDir%>" /><i18n:message key="rsf.title" />
              <ec2m:sortI18NColumn sortCol="<%=sortCol%>" width="15%" name="sub_category_id" title="Sort by sub_category_id" sortDir="<%=sortDir%>" /><i18n:message key="type" />
              <ec2m:sortI18NColumn sortCol="<%=sortCol%>" width="15%" name="create_date" title="Sort by create_date" sortDir="<%=sortDir%>" /><i18n:message key="createdate" />
              <ec2m:sortI18NColumn sortCol="<%=sortCol%>" width="10%" name="create_user" title="Sort by create_user" sortDir="<%=sortDir%>" /><i18n:message key="createuser" />
              <th width="10%"><i18n:message key="option"/></th>
           </tr>
        </thead>
    </table>
	<div class="scroll">
	    <table>
            <tbody>
                <%
                if(v!=null&&v.size()>0){ 
                      for(RSFBean rsfBean:v){
                    	 
                %>
                <tr>
                   <td width="20" norwap><input type="checkbox" name="setId" value="<%=rsfBean.getId() %>"/></td>
                   <td width="49%" norwap <%=Formater.formatText(request.getParameter("adv_title")) %>>
                          <%=(rsfBean.getIsTop()==1)?"<img src='"+URLPath.IMG_DIR+"/top.gif' />":"" %>
                          <%=(rsfBean.getIsImg()==1)?"<img src='"+URLPath.IMG_DIR+"/images.png' />&nbsp;":""%><%=rsfBean.getTitle() %>
                   </td>
                   <td width="15%" style="text-align:center" norwap><%=rsfBean.getSubCategoryName() %></td>
                   <td width="15%" style="text-align:center" norwap><%=Formater.formatDateSimpleTime(rsfBean.getcDate())%></td>
                   <td width="10%" style="text-align:center" norwap><%=rsfBean.getcUser() %></td>
                   <td width="10%" norwap>
                   <a href="javascript:edit(<%=rsfBean.getId() %>);"><i18n:message key="edit"/></a>&nbsp;
                   </td>
                </tr>        
                <%
                      }
                } 
                %>
                
            </tbody>
        </table>
    </div>
</div>
<ec2m:PaginationBarTag itemTotal ="<%=total_num%>" itemPerPage="<%=num_per_page%>" currentPage="<%=current_page%>" styletype="1"/>
</div>
</form>
</body>
</html>